<template>
  <div class="search-history">
    <van-cell title="搜索历史">
      <div v-if="isDeleteShow">
        <span @click="$emit('update-histories',[])">全部删除</span>
        <span @click="isDeleteShow = false">完成</span>
      </div>
      <van-icon v-else 
                name="delete"
                @click="isDeleteShow = true"/>
    </van-cell>

    <!-- 具体历史内容 -->
    <van-cell :title="history"
              v-for="(history, index) in searchHistories"
              :key="index"
              @click="onDelete(history, index)">
      <van-icon 
              v-show="isDeleteShow"
              name="close"/>
              
    </van-cell>
  </div>
</template>

<script>
export default {
  data() {
    return {
      isDeleteShow:false
    }
  },
 props:{
   searchHistories:{
     type:Array,
     required:true
   }
 },
 methods: {
   onDelete(history,index){
     if (this.isDeleteShow) {
       this.searchHistories.splice(index, 1)
     }
     this.$emit('search', history)
   }
 },
}
</script>

<style>

</style>